<template>
	<view class="favorites-container">
		<view class="page-header">
			<text class="page-title">我的收藏</text>
		</view>

		<view class="content" v-if="favoritesList.length > 0">
			<view class="video-list">
				<view v-for="item in favoritesList" :key="item.id" class="video-item">
					<image class="video-cover" :src="item.cover" mode="aspectFill" @click="playVideo(item)"></image>
					<view class="video-info">
						<text class="video-title">{{ item.title }}</text>
						<text class="video-author">作者: {{ item.author }}</text>
						<text class="video-time">收藏时间: {{ item.collectTime }}</text>
					</view>
					<view class="action-btn" @click="removeFavorite(item.id)">
						<text class="action-icon">❌</text>
					</view>
				</view>
			</view>
		</view>

		<view class="empty-state" v-else>
			<text class="empty-icon">⭐</text>
			<text class="empty-text">暂无收藏内容</text>
			<text class="empty-desc">去发现精彩内容并收藏吧</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				favoritesList: []
			}
		},
		onShow() {
			this.loadFavorites();
		},
		methods: {
			loadFavorites() {
				const favorites = uni.getStorageSync('favorites') || [];
				this.favoritesList = favorites;
			},

			removeFavorite(videoId) {
				uni.showModal({
					title: '提示',
					content: '确定要取消收藏吗？',
					success: (res) => {
						if (res.confirm) {
							const updatedFavorites = this.favoritesList.filter(item => item.id !== videoId);
							uni.setStorageSync('favorites', updatedFavorites);
							this.favoritesList = updatedFavorites;
							uni.showToast({
								title: '已取消收藏',
								icon: 'success'
							});
						}
					}
				});
			},

			playVideo(video) {
				// 跳转到视频播放页面
				uni.navigateTo({
					url: `/pages/video/video?id=${video.id}`
				});
			}
		}
	}
</script>

<style scoped>
	.favorites-container {
		min-height: 100vh;
		background: #f5f5f5;
	}

	.page-header {
		background: white;
		padding: 30rpx;
		border-bottom: 1rpx solid #f0f0f0;
	}

	.page-title {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
	}

	.content {
		padding: 20rpx;
	}

	.video-list {
		display: flex;
		flex-direction: column;
		gap: 20rpx;
	}

	.video-item {
		background: white;
		border-radius: 16rpx;
		padding: 24rpx;
		display: flex;
		align-items: center;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
	}

	.video-cover {
		width: 160rpx;
		height: 120rpx;
		border-radius: 12rpx;
		margin-right: 24rpx;
	}

	.video-info {
		flex: 1;
		display: flex;
		flex-direction: column;
	}

	.video-title {
		font-size: 28rpx;
		color: #333;
		font-weight: 500;
		margin-bottom: 8rpx;
	}

	.video-author,
	.video-time {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 4rpx;
	}

	.action-btn {
		padding: 16rpx;
	}

	.action-icon {
		font-size: 32rpx;
	}

	.empty-state {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 100rpx 40rpx;
		text-align: center;
	}

	.empty-icon {
		font-size: 120rpx;
		margin-bottom: 30rpx;
	}

	.empty-text {
		font-size: 32rpx;
		color: #666;
		margin-bottom: 16rpx;
	}

	.empty-desc {
		font-size: 26rpx;
		color: #999;
	}
</style>